package tempo.timing;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddRider extends Activity
{

	private EditText name;
	private EditText startNumer;
	private Button add;
	private Button btnClear;
	private Button btnDelete;
	private EditText txtStartToRemove;
	private Button btnResetAll;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		setContentView(R.layout.add_rider);

		name = (EditText) findViewById(R.id.name);
		startNumer = (EditText) findViewById(R.id.number);

		btnClear = (Button) findViewById(R.id.btnClear);
		btnClear.setOnClickListener(new OnClickListener()
		{
			public void onClick(View v)
			{
				Race.getCurrent().Clear();
			}
		});

		txtStartToRemove = (EditText) findViewById(R.id.txtStartToRemove);
		btnDelete = (Button) findViewById(R.id.btnDelete);
		btnDelete.setOnClickListener(new OnClickListener()
		{
			public void onClick(View v)
			{
				String sNum = txtStartToRemove.getText().toString();
				if(Race.getCurrent().delete(sNum))
					Toast.makeText(getBaseContext(), sNum + " deleted", Toast.LENGTH_SHORT).show();
			}
		});

		add = (Button) findViewById(R.id.add);
		add.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				String rname = name.getText().toString();
				Race.getCurrent().AddRider(rname, startNumer.getText().toString());
				Toast.makeText(getBaseContext(), rname + " added", Toast.LENGTH_SHORT).show();
			}
		});

		btnResetAll = (Button) findViewById(R.id.btnResetAll);
		btnResetAll.setOnClickListener(new View.OnClickListener()
		{
			public void onClick(View v)
			{
				Race.getCurrent().resetAll();
			}
		});
	}

}
